import Vue from "vue"
import Vuex from "vuex"
import VuexPersist from "vuex-persist"
Vue.use(Vuex)
const persist = new VuexPersist({
    storage :window.sessionStorage
})

export default new Vuex.Store({
    plugins:[persist.plugin],
    strict:true,
    //根状态
    state:{name:"小明"},
    mutations:{
        setName(state,data){
            state.name=data;
        }
    },
    //模块
    modules:{
        A:{
            namespaced:true,//开启命名空间,使模块拥有自己的作用域
            state:{ list:[{id:1,text:"我是模块A"}] },
            mutations:{
                setList(state,data){
                    state.list.push(data)
                }
            }
        },
        B:{
            namespaced:true,
            state:{ names:["银杏树","杨树"] },
            mutations:{
                setNames(state,data){
                    state.names.push(data)
                }
            }
        }
    }
})